﻿using System;
using System.Globalization;

namespace DataModel.Managers.SubManage
{
    public class WeekHelper
    {
        
        /// <summary>
        /// Get offset according entrance dates
        /// </summary>
        /// <param name="date"></param>
        /// <param name="offsetDate"></param>
        /// <returns></returns>
        public static int OffsetFirstWeek(DateTime date,DateTime offsetDate)
        {
            int offsetIndex = CultureInfo.CurrentCulture.Calendar.GetWeekOfYear(offsetDate, CalendarWeekRule.FirstDay, DayOfWeek.Monday);
            int currentIndex = CultureInfo.CurrentCulture.Calendar.GetWeekOfYear(date, CalendarWeekRule.FirstDay, DayOfWeek.Monday);
            return (currentIndex % offsetIndex + 1);
        }


        /// <summary>
        /// Current Study week offset 1 september
        /// </summary>
        /// <returns></returns>
        public static int GetCurrnetStudyWeekNumber()
        {
            var septemberBegin = new DateTime(DateTime.Now.Year, 9, 1); // Base Index
            return OffsetFirstWeek(DateTime.Now, septemberBegin);
        }

        /// <summary>
        /// Get Number of Study week
        /// </summary>
        /// <param name="date"></param>
        /// <returns></returns>
        public static int GetStudyWeekNumber(DateTime date)
        {
            var septemberBegin = new DateTime(DateTime.Now.Year, 9, 1); // Base Index
            return OffsetFirstWeek(date, septemberBegin);
        }
    }
}